/*头文件声明区*/
#include <STC15F2K60S2.H>
#include <Key.H>
#include <Seg.H>
#include <Led.H>
#include <init.h>
/*变量声明区域*/
unsigned char ksd;
unsigned char ssd;
unsigned char Seg_Point[8]={0,0,0,0,0,0,0,0};
unsigned char Seg_Pos;
unsigned char Seg_Buf[8]={10,10,10,10,10,10,10,10};
unsigned char ucLed[8]={0,0,0,0,0,0,0,0};
unsigned int time_1000ms;
bit L=0;//控制Led闪烁
/*按键处理函数*/
void Key_Proc()
{
	static unsigned char kv,kd,ku,ko;
	if(ksd!=0) return;
	ksd=1;
	kv=Key_Read();
	kd=kv&(kv^ko);
	ku=~kv&(kv^ko);
	ko=kv;
	
	switch(kd)
	{
		case 4:
			
		break;
		case 5:
			
		break;
		case 6:
			
		break;
		case 7:
			
		break;
	}
}

/*信息处理函数*/
void Seg_Proc()
{
	if(ssd!=0)return;
	ssd=1;
	
}
/*其他显示函数*/
void Led_Proc()
{
	if(L) ucLed[1]=0;
	else ucLed[1]=1;
}

/*定时器0初始化函数*/
void Timer0Init()		//1毫秒@12.000MHz
{
	AUXR &= 0x7F;		//定时器时钟12T模式
	TMOD &= 0xF0;		//设置定时器模式
	TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	TF0 = 0;		//清除TF0标志
	TR0 = 1;		//定时器0开始计时
	ET0=1;
	EA=1;
}


/*定时器0中断服务函数*/
void Timer0_Server() interrupt 1
{
	if(++ksd==10)ksd=0;
	if(++ssd==500)ssd=0;
	if(++Seg_Pos==8)Seg_Pos=0;
	Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Seg_Point[Seg_Pos]);
	Led_Disp(Seg_Pos,ucLed[Seg_Pos]);
	if(++time_1000ms==500)
	{
		time_1000ms=0;
		L^=1
	}
}

/*Main*/
void main()
{
	Timer0Init();
	System_Init();
	while(1)
	{
		Key_Proc();
		Seg_Proc();
		Led_Proc();
	}
}
